﻿using System;
using System.Diagnostics;
using WJP.ObjectModel;

namespace WJP.MetaModel
{
    /// <summary>
    /// 实体元数据
    /// </summary>
    [DebuggerDisplay("EntityMeta:{DebuggerDisplay}")]
    public class EntityMeta : Meta
    {
        private Type _entityType;
        /// <summary>
        /// 当前模型是对应这个类型的。
        /// </summary>
        public Type EntityType
        {
            get
            {
                return _entityType;
            }
            set
            {
                SetValue(ref _entityType, value, nameof(EntityType));
            }
        }

        private Type _idType;
        /// <summary>当前模型是对应这个类型的。</summary>
        public Type IdType
        {
            get
            {
                return this._idType;
            }
            set
            {
                this.SetValue<Type>(ref this._idType, value, nameof(IdType));
            }
        }

        private bool _IsTreeEntity;

        /// <summary>是否为树型实体。</summary>
        public bool IsTreeEntity
        {
            get
            {
                return this._IsTreeEntity;
            }
            set
            {
                this.SetValue<bool>(ref this._IsTreeEntity, value, nameof(IsTreeEntity));
            }
        }

        private TreeIndexOption _TreeIndexOption;

        /// <summary>如果是树型实体，则可以通过这个属性来设置它的树型编码存储规则。</summary>
        public TreeIndexOption TreeIndexOption
        {
            get
            {
                return this._TreeIndexOption;
            }
            set
            {
                this.SetValue(ref this._TreeIndexOption, value, nameof(TreeIndexOption));
            }
        }

        [UnAutoFreeze]
        private EntityMeta _AggtParent;
        /// <summary>聚合父类的元数据</summary>
        public EntityMeta AggtParent
        {
            get
            {
                return this._AggtParent;
            }
            set
            {
                this.SetValue(ref this._AggtParent, value, nameof(AggtParent));
            }
        }

        /// <summary>聚合根类的元数据</summary>
        public EntityMeta AggtRoot
        {
            get
            {
                return _AggtParent != null ? _AggtParent.AggtRoot : this;
            }
        }

        private EntityCategory _EntityCategory;
        /// <summary>实体的类别</summary>
        public EntityCategory EntityCategory
        {
            get
            {
                return this._EntityCategory;
            }
            set
            {
                this.SetValue(ref this._EntityCategory, value, nameof(EntityCategory));
            }
        }

        private bool _ServerCacheDefinition;
        private bool _DeletingChildrenInMemory;
        private bool _IsPhantomEnabled;

        /// <summary>
        /// 类型名
        /// </summary>
        public override string Name
        {
            get
            {
                return this.EntityType.Name;
            }
            set
            {
                throw new NotSupportedException();
            }
        }
    }
}